package com.example.jedis_pool.test;

import com.example.jedis_pool.jedis_config.Config;
import com.sun.deploy.util.BlackList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;

import java.util.List;

public class testString {

    public static void main(String[] args) {

        testString.setKeyValue();
        testString.getKeyValue();
        //关闭连接
        jedis.close();
    }
    //获取连接
     private static Jedis jedis=Config.JedisPool().getResource();

    //创建string0到string5
     public static void setKeyValue(){

         jedis.set("string0","string-value");
         jedis.setex("string6",120,"string-value-6");//过期时间120秒
         jedis.append("string0","-0");//若key不存在，则创建可以，并将value添加进key

         jedis.mset("string1","string-value-1", "string2","string-value-2",
                 "string3","string-value-3","string4","string-value-4","string4","string-value-4");
         System.out.println("string0的长度为："+jedis.strlen("string0"));//获取value值字符串的长度
         jedis.msetnx("string5","string-value-5");//可以同时创建多个key-value，当且仅当key不存在，若key存在则创建失败，失败则所有添加都失败

    }

    public static void getKeyValue(){

        List<String> list= jedis.mget("string0","string1","string2","string3","string4","string5");
        String s = jedis.getrange("string0",2,6);
        System.out.println("string0的2-6位置的字符："+s);//[闭区间]
        System.out.println(list);

    }

}
